﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using yq.IBase.DBHelper;

namespace yq.IBase.Basis
{
    /// <summary>
    /// 水平分割实体类
    /// 水平分割的表请改为继承这个对象
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public abstract class CutModelBase<T> : ModelBase<T> where T : ModelBase<T>, new()
    {
        /// <summary>
        /// 返回当前对象水平切割表的集合
        /// </summary>
        /// <returns></returns>
        public abstract IList<string> GetTableNameByCut();

        /// <summary>
        /// 根据当前对象,获取表名
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public abstract string GetTableNameByCut(T t);

        /// <summary>
        /// 根据Id,获取表名
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public abstract string GetTableNameByCut(string id);

        /// <summary>
        /// 生成一个新ID，这个ID要能区分水平分割的表名
        /// </summary>
        /// <returns></returns>
        public abstract string GetNewsId();

        /// <summary>
        /// 根据主键获取选择性的SQL语句
        /// </summary>
        /// <param name="aat_id">主键值</param>
        /// <returns></returns>
        protected internal override string GetSelectKey(string id)
        {
            string tableName = GetTableNameByCut(id);
            SelectSQL sql = new SelectSQL()
            {
                Table = tableName,
                WhereString=" Where " + GetTableKey() + " = '" + id + "'"
            };
            GetSelectSql(sql);

            return sql.toSql();
        }
       
    }
}
